﻿using System;
using System.Collections.Generic;
using Helpers;
using TaleWorlds.CampaignSystem.Settlements;
using TaleWorlds.Library;
using TaleWorlds.Localization;
using TaleWorlds.ObjectSystem;
using TaleWorlds.SaveSystem;

namespace TaleWorlds.CampaignSystem.LogEntries
{
	// Token: 0x020002E6 RID: 742
	public class TournamentWonLogEntry : LogEntry, IEncyclopediaLog, IChatNotification
	{
		// Token: 0x06002B6F RID: 11119 RVA: 0x000B7FD4 File Offset: 0x000B61D4
		internal static void AutoGeneratedStaticCollectObjectsTournamentWonLogEntry(object o, List<object> collectedObjects)
		{
			((TournamentWonLogEntry)o).AutoGeneratedInstanceCollectObjects(collectedObjects);
		}

		// Token: 0x06002B70 RID: 11120 RVA: 0x000B7FE2 File Offset: 0x000B61E2
		protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
		{
			base.AutoGeneratedInstanceCollectObjects(collectedObjects);
			collectedObjects.Add(this._participants);
			collectedObjects.Add(this.Winner);
			collectedObjects.Add(this.Town);
		}

		// Token: 0x06002B71 RID: 11121 RVA: 0x000B800F File Offset: 0x000B620F
		internal static object AutoGeneratedGetMemberValueWinner(object o)
		{
			return ((TournamentWonLogEntry)o).Winner;
		}

		// Token: 0x06002B72 RID: 11122 RVA: 0x000B801C File Offset: 0x000B621C
		internal static object AutoGeneratedGetMemberValueTown(object o)
		{
			return ((TournamentWonLogEntry)o).Town;
		}

		// Token: 0x06002B73 RID: 11123 RVA: 0x000B8029 File Offset: 0x000B6229
		internal static object AutoGeneratedGetMemberValue_participants(object o)
		{
			return ((TournamentWonLogEntry)o)._participants;
		}

		// Token: 0x17000AAB RID: 2731
		// (get) Token: 0x06002B74 RID: 11124 RVA: 0x000B8036 File Offset: 0x000B6236
		// (set) Token: 0x06002B75 RID: 11125 RVA: 0x000B803E File Offset: 0x000B623E
		[SaveableProperty(931)]
		public Hero Winner { get; private set; }

		// Token: 0x17000AAC RID: 2732
		// (get) Token: 0x06002B76 RID: 11126 RVA: 0x000B8047 File Offset: 0x000B6247
		// (set) Token: 0x06002B77 RID: 11127 RVA: 0x000B804F File Offset: 0x000B624F
		[SaveableProperty(932)]
		public Town Town { get; private set; }

		// Token: 0x17000AAD RID: 2733
		// (get) Token: 0x06002B78 RID: 11128 RVA: 0x000B8058 File Offset: 0x000B6258
		public bool IsVisibleNotification
		{
			get
			{
				return true;
			}
		}

		// Token: 0x17000AAE RID: 2734
		// (get) Token: 0x06002B79 RID: 11129 RVA: 0x000B805B File Offset: 0x000B625B
		public override ChatNotificationType NotificationType
		{
			get
			{
				return base.CivilianNotification(this.Winner.Clan);
			}
		}

		// Token: 0x06002B7A RID: 11130 RVA: 0x000B8070 File Offset: 0x000B6270
		public TournamentWonLogEntry(Hero winner, Town town, MBReadOnlyList<CharacterObject> gameParticipants)
		{
			this.Winner = winner;
			this.Town = town;
			Dictionary<Hero, short> dictionary = new Dictionary<Hero, short>();
			foreach (CharacterObject characterObject in gameParticipants)
			{
				if (characterObject.HeroObject != null && !dictionary.ContainsKey(characterObject.HeroObject))
				{
					dictionary.Add(characterObject.HeroObject, 1);
				}
			}
			this._participants = dictionary.GetReadOnlyDictionary<Hero, short>();
		}

		// Token: 0x06002B7B RID: 11131 RVA: 0x000B8100 File Offset: 0x000B6300
		public override string ToString()
		{
			return "Tournament won";
		}

		// Token: 0x06002B7C RID: 11132 RVA: 0x000B8107 File Offset: 0x000B6307
		public TextObject GetEncyclopediaText()
		{
			return this.GetNotificationText();
		}

		// Token: 0x06002B7D RID: 11133 RVA: 0x000B8110 File Offset: 0x000B6310
		public TextObject GetNotificationText()
		{
			TextObject textObject = new TextObject("{=4ADQ7YZj}{PERSON.LINK} won the tournament at {TOWN}.", null);
			StringHelpers.SetCharacterProperties("PERSON", this.Winner.CharacterObject, textObject, false);
			textObject.SetTextVariable("TOWN", this.Town.Name);
			return textObject;
		}

		// Token: 0x06002B7E RID: 11134 RVA: 0x000B8159 File Offset: 0x000B6359
		public bool IsVisibleInEncyclopediaPageOf<T>(T obj) where T : MBObjectBase
		{
			return obj == this.Winner || obj == this.Winner.Clan || obj == this.Town.Settlement;
		}

		// Token: 0x06002B7F RID: 11135 RVA: 0x000B8194 File Offset: 0x000B6394
		public override void GetConversationScoreAndComment(Hero talkTroop, bool findString, out string comment, out ImportanceEnum score)
		{
			short num;
			if (!this._participants.TryGetValue(talkTroop, out num))
			{
				num = -2;
			}
			short num2;
			if (!this._participants.TryGetValue(Hero.MainHero, out num2))
			{
				num2 = -2;
			}
			score = ImportanceEnum.Zero;
			comment = "";
			if (num > 0 && num2 > 0)
			{
				score = ImportanceEnum.SomewhatImportant;
				if (findString)
				{
					MBTextManager.SetTextVariable("TOURNAMENT_TOWN", this.Town.Name, false);
					MBTextManager.SetTextVariable("TOURNAMENT_WINNER", this.Winner.Name, false);
					if (this.Winner == Hero.MainHero)
					{
						comment = "str_comment_you_won_tournament_elsewhere";
						if (this.Town.Settlement == Settlement.CurrentSettlement)
						{
							comment = "str_comment_you_won_tournament_here";
							return;
						}
					}
					else if (this.Winner == talkTroop)
					{
						comment = "str_comment_i_won_tournament_elsewhere";
						if (this.Town.Settlement == Settlement.CurrentSettlement)
						{
							comment = "str_comment_i_won_tournament_here";
							return;
						}
					}
					else
					{
						comment = "str_comment_someone_else_won_tournament_elsewhere";
						if (this.Town.Settlement == Settlement.CurrentSettlement)
						{
							comment = "str_comment_someone_else_won_tournament_here";
						}
					}
				}
			}
		}

		// Token: 0x04000D06 RID: 3334
		[SaveableField(934)]
		private MBReadOnlyDictionary<Hero, short> _participants;
	}
}
